package com.stars.easyms.mq.core;

import com.stars.easyms.mq.asyn.AsynReceiveMQMessage;
import com.stars.easyms.mq.core.activemq.ActiveMQListener;
import com.stars.easyms.mq.core.rocketmq.RocketMQListener;
import com.stars.easyms.mq.dto.MQInfoDTO;
import com.stars.easyms.mq.enums.MQ;
import com.stars.easyms.mq.properties.EasyMsMQProperties;
import com.stars.easyms.mq.service.MQMessageService;
import org.springframework.context.ApplicationContext;

/**
 * MQ监听器工厂类
 *
 * @author guoguifang
 * @date 2018-04-23 13:54
 * @since 1.0.0
 */
public class MQListenerFactory {

    private ApplicationContext applicationContext;
    private String applicationId;
    private EasyMsMQProperties easyMsMQProperties;
    private MQMessageService mqMessageService;
    private AsynReceiveMQMessage asynReceiveMQMessage;

    public MQListener getMQListener(MQInfoDTO mqInfoDTO, String key) {
        if (easyMsMQProperties.getActive() == MQ.ACTIVEMQ) {
            return new ActiveMQListener(applicationContext, applicationId, easyMsMQProperties, mqMessageService, asynReceiveMQMessage, mqInfoDTO, key);
        }
        return new RocketMQListener(applicationId, easyMsMQProperties, mqMessageService, asynReceiveMQMessage, mqInfoDTO, key);
    }

    public MQListenerFactory(ApplicationContext applicationContext, String applicationId, EasyMsMQProperties easyMsMQProperties, MQMessageService mqMessageService, AsynReceiveMQMessage asynReceiveMQMessage) {
        this.applicationContext = applicationContext;
        this.applicationId = applicationId;
        this.easyMsMQProperties = easyMsMQProperties;
        this.mqMessageService = mqMessageService;
        this.asynReceiveMQMessage = asynReceiveMQMessage;
    }

}
